package com.wang.ymcc.web.controller;

import com.alibaba.fastjson.JSON;
import com.google.code.kaptcha.Producer;
import com.wang.lwm.result.JSONResult;
import com.wang.lwm.util.Base64;
import com.wang.ymcc.config.RuoYiConfig;
import com.wang.ymcc.dot.SmsCodeDto;
import com.wang.ymcc.properties.CacheConstants;
import com.wang.ymcc.properties.Constants;
import com.wang.ymcc.redis.RedisCache;
import com.wang.ymcc.service.ICommonService;
import com.wang.ymcc.service.ISysConfigService;
import com.wang.ymcc.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/verifycode")
public class CommonController {

    @Autowired
    private ICommonService commonService;

    @Autowired
    private ISysConfigService configService;

    @Resource(name = "captchaProducer")
    private Producer captchaProducer;

    @Resource(name = "captchaProducerMath")
    private Producer captchaProducerMath;

    @Autowired
    private RedisCache redisCache;
    /*
        图形验证码
     */
    @GetMapping("/imageCode")
    public JSONResult getImageCode(HttpServletResponse response){
        String base64Str = commonService.getImageCode(response);
        return JSONResult.success(base64Str);
    }

    /*
        手机验证码
     */
    @PostMapping("/sendSmsCode")
    public JSONResult getSms(@Valid @RequestBody SmsCodeDto smscodedto){
        commonService.getSms(smscodedto);
        return JSONResult.success();
    }


}
